package com.stack.search.controller.v1;

import com.alibaba.fastjson.JSON;
import com.stack.model.common.dtos.ResponseResult;
import com.stack.model.search.dtos.HistorySearchDto;
import com.stack.search.service.ApUserSearchService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;
/**
 * @author llz
 * @date 2023/10/13 0:59
 * @description 历史搜索关键词处理
 */
@RestController
@RequestMapping("/api/v1/history")
public class ApUserSearchController {

    @Autowired
    private ApUserSearchService apUserSearchService;

    @PostMapping("/load")
    public ResponseResult findUserSearch(){
        return apUserSearchService.findUserSearch();
    }

    //原来前端传的是String
    @PostMapping("/del")
    public ResponseResult delUserSearch(@RequestBody String dto){
        Map<String,String> map = JSON.parseObject(dto, Map.class);
        String id = map.get("id");
        HistorySearchDto searchDto = new HistorySearchDto(id);
        return apUserSearchService.delUserSearch(searchDto);
    }
}
